package com.xinqi.modules.file.course.homework.service.impl;

import com.xinqi.common.core.utils.StringUtils;
import com.xinqi.common.base.utils.json.JSON;
import com.xinqi.modules.file.course.homework.domain.CourseHomeworkFileEntity;
import com.xinqi.modules.file.course.homework.mapper.CourseHomeworkFileMapper;
import com.xinqi.modules.file.course.homework.service.HomeworkService;
import lombok.RequiredArgsConstructor;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class HomeworkServiceImpl implements HomeworkService {

    private final CourseHomeworkFileMapper homeworkFileMapper;

    /**
     * 阿里作业切片方法
     * @author dzy
     */
    @Override
    public boolean sliceOssFile(Long key, List<String> fileUrls) {
        CourseHomeworkFileEntity checkEntity = homeworkFileMapper.selectById(key);
        if (StringUtils.isEmpty(checkEntity.getFiletransformimg())) {
            if (CollectionUtils.isNotEmpty(fileUrls)) {
                CourseHomeworkFileEntity entity = new CourseHomeworkFileEntity();
                entity.setId(key);
                entity.setFiletransformimg(JSON.stringify(fileUrls));
                return homeworkFileMapper.updateById(entity) > 0;
            } else {
                return false;
            }
        }
        return true;
    }

}
